// createStore 创建redux仓库
import {legacy_createStore as createStore} from 'redux';

// 定义仓库初始化状态
let initState = {
    num:0,
    name:"张三"
}

// 创建reducer处理函数
let reducer = (state=initState,action)=>{
    console.log(action)
    switch(action.type){
        case 'ADD':
            let newState = {...state};
            newState.num+=action.num;
            return newState
        case 'REDUCE':
            let myState = {...state};
            myState.num-=action.num;
            return myState;
        default :
        return state
    }
}

//创建仓库 参数为reducer处理函数
let store = createStore(reducer);


export default store;

/* 
redux 设计三原则：
1. 状态是唯一。
2. state状态是只读的，更新需要返回新状态
3. reducer必须是纯函数
*/